package com.escool.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.escool.model.TbGrado;
import com.escool.model.TbNivel;

import com.escool.model.TbActividad;


import com.escool.service.CatEventoService;
import com.escool.service.GradosService;
import com.escool.service.NivelesService;
import com.escool.service.RolService;

@Controller
public class CatEventoController {
	
	@Autowired
	CatEventoService CatActividadService;

	
	@RequestMapping("showCatActividad")
	public String showCatActividad(Map<String, Object> map){
		map.put("CatActividad", new TbActividad());
		map.put("TbActividadList", CatActividadService.listTbActividad());
		return "/catActividad";
	}
	
	@RequestMapping(value = "addCatActividad", method = RequestMethod.POST)
	public String addRoles(@ModelAttribute("CatActividad") @Valid TbActividad tbCatActividad, BindingResult result){
		if (!result.hasErrors()) {
			CatActividadService.addTbActividad(tbCatActividad);
			return "redirect:/showCatActividad";
		}
		return "";
	}
	
	@RequestMapping(value = "editCatActividad", method = RequestMethod.POST)
	public String editRoles(@ModelAttribute("CatActividad") @Valid TbActividad tbCatActividad, BindingResult result){
		if (!result.hasErrors()) {
			CatActividadService.editTbActividad(tbCatActividad);
			return "redirect:/showCatActividad";
		}
		return "";
	}
	
	@RequestMapping(value = "deleteCatActividad", method = RequestMethod.POST)
	public String delRoles(@ModelAttribute("CatActividad") @Valid TbActividad tbCatActividad, BindingResult result){
		if (!result.hasErrors()) {
			CatActividadService.delTbActividad(tbCatActividad.getIdActividad());
			return "redirect:/showCatActividad";
		}
		return "";
	}

}
